from selenium.webdriver.common.by import By

from page_object.pages.BasePage import BasePage
from page_object.pages.ChatRoom import ChatRoom


class SearchPage(BasePage):
    # 搜索页
    _et_search = (By.ID, 'et_search')

    def search_room(self, room_id):
        '''
        搜索房间
        :param room_id:房间id
        :return: 聊天室页面
        '''

        search_result = (By.XPATH, '//*[contains(@resource-id, "tv_room_id") and contains(@text, "%s")]' %room_id)
        self.find(self._et_search).send_keys(room_id)
        # 没有点击搜索按钮，只能切换页签再切换回来搜索
        self.find_by_xpath('用户').click()
        self.find_by_xpath('聊天室').click()
        self.find(search_result).click()
        return ChatRoom()

    def search_history(self, room_id):
        '''
        点击搜索历史
        :param room_id: 房间id 必须是搜索历史里面有的
        :return: 聊天室页面
        '''

        search_room_history = (By.XPATH, '//*[contains(@resource-id, "textItem") and contains(@text, "%s")]' %room_id)
        search_result = (By.XPATH, '//*[contains(@resource-id, "tv_room_id") and contains(@text, "%s")]' % room_id)

        self.find(search_room_history).click()
        self.find(search_result).click()
        return ChatRoom()



